function generateModelEulerErrorPruning_file(allModelParams,x,y,xp,yp,strucOfArrays,positionFile,nameOfFunction)
% This function generates an M function which computes the Euler equation errors 
% using the Pruning scheme.
% The results are saved in the file nameOfFunction, for instance 
% nameOfFunction = 'EulerEqErrorPruning.m';

% We start deleting the old version of the file - if it exists
saveFile = [positionFile,'\',nameOfFunction];
if exist(saveFile,'file') > 0
    delete(saveFile)
end
text = ['function [ResEuler,yGrid] = ',nameOfFunction(1:end-2),'(model,orderApp,setup)'];
dlmwrite(saveFile,text,'-append','delimiter','');
text = ' ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '% Some indices ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = 'ny      = model.ny;        %Number of output variables';
dlmwrite(saveFile,text,'-append','delimiter','');
text = 'nx      = model.nx;        %Number of state variables ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = 'derivs  = model.derivs;    %Deviatives as stored by Levintal ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = ' ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '%Unfold params';
dlmwrite(saveFile,text,'-append','delimiter','');
for i=1:length(allModelParams)
    text = [allModelParams{i}, '= model.params.',allModelParams{i},';'];
    dlmwrite(saveFile,text,'-append','delimiter','');
end 
text = ' ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '% The raw grid for the states ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = 'xGrid_f = setup.xSim_decom.xt_f; ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = 'if orderApp >= 2 ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    xGrid_s = setup.xSim_decom.xt_s; ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = 'end ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = 'if orderApp >= 3 ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    xGrid_rd = setup.xSim_decom.xt_rd; ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = 'end ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = 'if orderApp >= 4 ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    xGrid_4th = setup.xSim_decom.xt_4th; ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = 'end';
dlmwrite(saveFile,text,'-append','delimiter','');
text = 'if orderApp >= 5 ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    xGrid_5th = setup.xSim_decom.xt_5th; ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = 'end';
dlmwrite(saveFile,text,'-append','delimiter','');
text = ' ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = ' ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '% The grid for numerical itegration ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = 'tmp_e        = cell(1,model.ne); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = 'tmp_w        = cell(1,model.ne); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = 'for i=1:model.ne ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    tmp_e(i) = mat2cell(setup.GH_e,length(setup.GH_e),1); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    tmp_w(i) = mat2cell(setup.GH_w,length(setup.GH_w),1); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = 'end ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = 'eGrid = cartprod(tmp_e); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = 'wGrid = prod(cartprod(tmp_w),2); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = ' ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '%% Building the residuals ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = 'f        = zeros(ny+nx,1); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = 'ResEuler = zeros(size(xGrid_f,2),ny+nx); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = 'yGrid    = zeros(size(xGrid_f,2),ny); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '% Setting the dimensions for the state components ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = 'xf_cu    = [zeros(nx,1);1]; ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = 'xs_cu    = [zeros(nx,1);0]; ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = 'xrd_cu   = [zeros(nx,1);0]; ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = 'x4th_cu  = [zeros(nx,1);0]; ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = 'x5th_cu  = [zeros(nx,1);0]; ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = ' ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = 'xf_cup   = [zeros(nx,1);1]; ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = 'xs_cup   = [zeros(nx,1);0]; ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = 'xrd_cup  = [zeros(nx,1);0]; ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = 'x4th_cup = [zeros(nx,1);0]; ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = 'x5th_cup = [zeros(nx,1);0]; ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = ' ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = 'for k = 1:size(xGrid_f,2) ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    xf_cu    = xGrid_f(:,k); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    if orderApp>=2 ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '        xs_cu  = xGrid_s(:,k); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    end ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    if orderApp>=3 ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '        xrd_cu  = xGrid_rd(:,k); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    end ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    if orderApp>=4 ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '        x4th_cu  = xGrid_4th(:,k); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    end ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    if orderApp>=5 ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '        x5th_cu  = xGrid_5th(:,k); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    end ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = ' ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    % Getting the states at time t ';
dlmwrite(saveFile,text,'-append','delimiter','');
for i=1:length(x)
     text = ['    ',char(x(i)),' = model.h0(',num2str(i),',1) + xf_cu(', num2str(i),',1) + xs_cu(', num2str(i),',1) + xrd_cu(', num2str(i),',1) + x4th_cu(', num2str(i),',1) + x5th_cu(', num2str(i),',1);'];
     dlmwrite(saveFile,text,'-append','delimiter','');
end
text = ' ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    % Getting the states at time t+1 ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    xf_cup(1:end-1,1)     = derivs.hx*xf_cu; ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    if orderApp>=2 ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '        xf2_cu            = kron(xf_cu,xf_cu); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '        xs_cup(1:end-1,1) = derivs.hx*xs_cu + derivs.hxx*xf2_cu/2; ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    end ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    if orderApp>=3 ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '        xf3_cu             = kron(xf2_cu,xf_cu); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '        xf_xs_cu           = kron(xf_cu,xs_cu); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '        xrd_cup(1:end-1,1) = derivs.hx*xrd_cu + derivs.hxx*(2*xf_xs_cu)/2 ... ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '                            + derivs.hxxx*xf3_cu/6; ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    end ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    if orderApp>=4 ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '        xf4_cu             = kron(xf3_cu,xf_cu); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '        xf2_xs_cu          = kron(xf_cu,xf_xs_cu); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '        xs2_cu             = kron(xs_cu,xs_cu); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '        xf_xrd_cu          = kron(xf_cu,xrd_cu); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '        x4th_cup(1:end-1,1)= derivs.hx*x4th_cu + derivs.hxx*(2*xf_xrd_cu + xs2_cu)/2 ... ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '                            + derivs.hxxx*(3*xf2_xs_cu)/6 ... ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '                            + derivs.hxxxx*xf4_cu/24; ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    end ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    if orderApp>=5 ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '        xf5_cu             = kron(xf4_cu,xf_cu); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '        xf3_xs_cu          = kron(xf_cu,xf2_xs_cu); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '        xf_xs2_cu          = kron(xf_cu,xs2_cu); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '        xf2_xrd_cu         = kron(xf_cu,xf_xrd_cu); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '        xs_xrd_cu          = kron(xs_cu,xrd_cu); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '        xf_x4th_cu         = kron(xf_cu,x4th_cu); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '        x5th_cup(1:end-1,1)= derivs.hx*x5th_cu ... ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '                            + derivs.hxx*(2*xf_x4th_cu+2*xs_xrd_cu)/2 ... ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '                            + derivs.hxxx*(3*xf2_xrd_cu+3*xf_xs2_cu)/6 ... ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '                            + derivs.hxxxx*(4*xf3_xs_cu)/24 ... ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '                            + derivs.hxxxxx*xf5_cu/120; ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    end ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    % Getting the controls at time t ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    if orderApp==1 ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '        yVec_cu = model.g0 + derivs.gx*xf_cu; ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    elseif orderApp==2 ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '        yVec_cu = model.g0 + derivs.gx*(xf_cu+xs_cu)+derivs.gxx*(xf2_cu)/2; ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    elseif orderApp==3 ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '        yVec_cu = model.g0 + derivs.gx*(xf_cu+xs_cu+xrd_cu)+derivs.gxx*(xf2_cu+2*xf_xs_cu)/2 ... ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '            + derivs.gxxx*(xf3_cu)/6; ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    elseif orderApp==4 ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '        yVec_cu = model.g0 + derivs.gx*(xf_cu+xs_cu+xrd_cu+x4th_cu) ... ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '            + derivs.gxx*(xf2_cu+2*xf_xs_cu+2*xf_xrd_cu+xs2_cu)/2 ... ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '            + derivs.gxxx*(xf3_cu+3*xf2_xs_cu)/6 ... ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '            + derivs.gxxxx*xf4_cu/24; ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    elseif orderApp==5 ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '        yVec_cu = model.g0 + derivs.gx*(xf_cu+xs_cu+xrd_cu+x4th_cu+x5th_cu) ... ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '            + derivs.gxx*(xf2_cu+2*xf_xs_cu+2*xf_xrd_cu+2*xf_x4th_cu+xs2_cu+2*xs_xrd_cu)/2 ... ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '            + derivs.gxxx*(xf3_cu+3*xf2_xs_cu+3*xf2_xrd_cu+3*xf_xs2_cu)/6 ... ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '            + derivs.gxxxx*(xf4_cu+4*xf3_xs_cu)/24 ... ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '            + derivs.gxxxxx*xf5_cu/120; ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    end ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    yGrid(k,:) = transpose((yVec_cu-model.g0)); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    % The controls ';
dlmwrite(saveFile,text,'-append','delimiter','');
for i=1:length(y)
     text = ['    ',char(y(i)),' = yVec_cu(', num2str(i),',1);'];
     dlmwrite(saveFile,text,'-append','delimiter','');
end
text = ' ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    Euler = zeros(ny+nx,1);';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    xf_cup0 = xf_cup;';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    for i=1:length(wGrid)';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '        % Adding shocks to the states ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '        xf_cup(1:nx,1) = xf_cup0(1:nx,1) + model.eta*transpose(eGrid(i,:)); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '        % Getting controls at time t+1 ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '        if orderApp==1 ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '            yVec_cup  = model.g0 + derivs.gx*xf_cup; ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '        elseif orderApp==2 ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '            xf2_cup   = kron(xf_cup,xf_cup); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '            yVec_cup  = model.g0 + derivs.gx*(xf_cup+xs_cup)+derivs.gxx*(xf2_cup)/2; ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '        elseif orderApp==3 ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '            xf2_cup   = kron(xf_cup,xf_cup); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '            xf3_cup   = kron(xf2_cup,xf_cup); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '            xf_xs_cup = kron(xf_cup,xs_cup); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '            yVec_cup  = model.g0 + derivs.gx*(xf_cup+xs_cup+xrd_cup)+derivs.gxx*(xf2_cup+2*xf_xs_cup)/2 ... ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '                + derivs.gxxx*(xf3_cup)/6; ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '        elseif orderApp==4 ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '            xf2_cup    = kron(xf_cup,xf_cup); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '            xf3_cup    = kron(xf2_cup,xf_cup); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '            xf_xs_cup  = kron(xf_cup,xs_cup); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '            xf4_cup    = kron(xf3_cup,xf_cup); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '            xf2_xs_cup = kron(xf_cup,xf_xs_cup); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '            xs2_cup    = kron(xs_cup,xs_cup); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '            xf_xrd_cup = kron(xf_cup,xrd_cup); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '            yVec_cup   = model.g0 + derivs.gx*(xf_cup+xs_cup+xrd_cup+x4th_cup) ... ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '                + derivs.gxx*(xf2_cup+2*xf_xs_cup+2*xf_xrd_cup+xs2_cup)/2 ... ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '                + derivs.gxxx*(xf3_cup+3*xf2_xs_cup)/6 ... ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '                + derivs.gxxxx*xf4_cup/24; ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '        elseif orderApp==5 ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '            xf2_cup    = kron(xf_cup,xf_cup); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '            xf3_cup    = kron(xf2_cup,xf_cup); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '            xf_xs_cup  = kron(xf_cup,xs_cup); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '            xf4_cup    = kron(xf3_cup,xf_cup); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '            xf2_xs_cup = kron(xf_cup,xf_xs_cup); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '            xs2_cup    = kron(xs_cup,xs_cup); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '            xf_xrd_cup = kron(xf_cup,xrd_cup); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '            xf5_cup    = kron(xf4_cup,xf_cup); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '            xf3_xs_cup = kron(xf_cup,xf2_xs_cup); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '            xf_xs2_cup = kron(xf_cup,xs2_cup); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '            xf2_xrd_cup= kron(xf_cup,xf_xrd_cup); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '            xs_xrd_cup = kron(xs_cup,xrd_cup); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '            xf_x4th_cup= kron(xf_cup,x4th_cup); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '            yVec_cup = model.g0 + derivs.gx*(xf_cup+xs_cup+xrd_cup+x4th_cup+x5th_cup) ... ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '                + derivs.gxx*(xf2_cup+2*xf_xs_cup+2*xf_xrd_cup+2*xf_x4th_cup+xs2_cup+2*xs_xrd_cup)/2 ... ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '                + derivs.gxxx*(xf3_cup+3*xf2_xs_cup+3*xf2_xrd_cup+3*xf_xs2_cup)/6 ... ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '                + derivs.gxxxx*(xf4_cup+4*xf3_xs_cup)/24 ... ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '                + derivs.gxxxxx*xf5_cup/120; ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '        end ';
dlmwrite(saveFile,text,'-append','delimiter','');
for i=1:length(yp)
     text = ['        ',char(yp(i)),' = yVec_cup(', num2str(i),',1);'];
     dlmwrite(saveFile,text,'-append','delimiter','');
end
text = ' ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '        % Getting the states at time t+1 ';
dlmwrite(saveFile,text,'-append','delimiter','');
for i=1:length(xp)
     text = ['        ',char(xp(i)),' = model.h0(',num2str(i),',1) + xf_cup(', num2str(i),',1) + xs_cup(', num2str(i),',1) + xrd_cup(', num2str(i),',1) + x4th_cup(', num2str(i),',1) + x5th_cup(', num2str(i),',1);'];
     dlmwrite(saveFile,text,'-append','delimiter','');
end
text = '        %% Model Specific ';
dlmwrite(saveFile,text,'-append','delimiter','');
DispSymMatrixMatlab_file(strucOfArrays.('f'),'f',saveFile);
text = '        Euler(:,1) = Euler(:,1) + wGrid(i,1)*f(:,1); ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    end ';
dlmwrite(saveFile,text,'-append','delimiter','');
text = '    ResEuler(k,:) = transpose(Euler(:,1));';
dlmwrite(saveFile,text,'-append','delimiter','');
text = 'end ';
dlmwrite(saveFile,text,'-append','delimiter','');

end